package com.eya;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * TODO(这个类的作用)
 *
 * @auther: luolin
 * @since: 2018/1/22 15:41
 */
@SpringBootApplication
@RestController
@RefreshScope//指示Config客户端在服务器参数刷新时，也刷新注入的属性值
public class ConfigClientApplication {

	public static void main(String[] args) {
		SpringApplication.run(ConfigClientApplication.class, args);
	}

	@Value("${mysqldb.datasource.username}")
	private String dataSourceUserName;

	@RequestMapping(value = "/hi")
	public String hi(){
		return dataSourceUserName;
	}

	/**
	 * 验证可以从Environment中获得配置
	 * @param env
	 */
	@Autowired
	void setEnviroment(Environment env) {
		System.out.println("my-config.appName from env: "
						   + env.getProperty("mysqldb.datasource.username"));
	}

}
